package cn.group.controller;

import cn.group.service.RoleManagerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.*;
import pojo.entity.Role;
import pojo.entity.RolePermission;
import pojo.qo.RolePermissionQO;
import pojo.vo.BaseRespVO;
import utils.BaseController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

@Api(tags = "角色管理")
@Configuration
@RequestMapping(value = "/roleManager", produces = "application/json;charset=utf-8")
public class RoleManagerController extends BaseController {

    @Autowired
    private RoleManagerService roleManagerService;

    @ApiOperation("添加角色")
    @RequestMapping(value = "addRoleMessage.do", method = RequestMethod.POST)
    @ResponseBody
    public String addRoleMessage(@RequestBody RolePermissionQO rolePermissionQO, HttpServletResponse response) {
        System.out.println("addRoleMessage-------------------------");
        return writerSuccessResult(roleManagerService.addRole(rolePermissionQO), response);
    }

    @ApiOperation("修改角色")
    @PostMapping("updateRolePermissionByIdMassage.do")
    @ResponseBody
    public String updateRolePermissionByIdMassage(@RequestBody RolePermissionQO rolePermissionQO, HttpServletResponse response) {
        return writerSuccessResult(roleManagerService.updateRolePermissionById(rolePermissionQO), response);
    }

    @ApiOperation("删除角色")
    @RequestMapping(value = "deleteRoleMessage.do", method = RequestMethod.POST)
    @ResponseBody
    public String deleteRoleMessage(@RequestBody Long roleId, HttpServletResponse response) {
        return writerSuccessResult(roleManagerService.deleteRole(roleId), response);
    }

    @ApiOperation("查看管理员列表")
    @GetMapping("showRoleMessageList.do")
    @ResponseBody
    public String showRoleMessageList(HttpServletResponse response) {
        return writerSuccessResult(roleManagerService.showRoleList(), response);
    }

    @ApiOperation("通过角色Id查看角色信息")
    @PostMapping("showRoleByIdMessage.do")
    @ResponseBody
    public String showRoleByIdMessage(@RequestBody Long id,HttpServletResponse response) {
        return writerSuccessResult(roleManagerService.showRolePermissionById(id), response);
    }
}
